The Traveling Salesman Problem (TSP) and Hamiltonian Path/Cycle problems are closely related, but they are not the same thing.
In a travelling salesman problem with 10 cities, the goal is to find the shortest possible route that starts at City A, visits each of the remaining nine cities exactly once, and returns to City A.
The number of possible directed tours is given by:
P(n) = (n − 1)!
For ten cities:
P(10) = 9! = 362,880
In an undirected TSP, a route and its reverse direction represent the same path. To remove these duplicates, the number of unique tours is:
U(n) = (n − 1)! / 2
For ten cities:
U(10) = 9! / 2 = 181,440
This means there are 181,440 unique undirected tours when reverse paths are treated as identical.
Click any cell to edit its weight. Use 1e9 to mark a forbidden transition.